/* vim: set ai et ts=4 sw=4: */
#include "stm32f4xx_hal.h"
#include "nt35510.h"
#include "string.h"
#include "stdio.h"

/* Static functions for fundamental instructions */
static void NT35510_HardwareInit() {
	//gpio inie
	/* GPIO_InitStruct */
    __HAL_RCC_GPIOB_CLK_ENABLE();
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	GPIO_InitStruct.Pin = NT35510_BL_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_PULLUP;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(NT35510_BL_GPIO_Port, &GPIO_InitStruct);
}

void NT35510_DelayMs(uint32_t tick) {
    HAL_Delay(tick);
}

/* Static functions for fundamental instructions */
void NT35510_Bl(char cmd) {
	if(cmd)
	{
		HAL_GPIO_WritePin(NT35510_BL_GPIO_Port,NT35510_BL_Pin,GPIO_PIN_SET);
	}
    else
    {
        HAL_GPIO_WritePin(NT35510_BL_GPIO_Port,NT35510_BL_Pin,GPIO_PIN_RESET);
    }

}
/* Static functions for fundamental instructions */
static void NT35510_Reset() {

}

static void NT35510_WriteCommand(uint16_t cmd) {
    NT35510_WRITE_REG = cmd;
}

static void NT35510_WriteData(uint16_t data) {
    NT35510_WRITE_DATA = data;
}


static uint16_t NT35510_ReadData(void)
{
	return NT35510_WRITE_DATA;		//返回读到的值
}


static void NT35510_SetRegister(uint16_t reg, uint16_t source) {
    NT35510_WriteCommand(reg);
    NT35510_WriteData(source);
}




//读取个某点的颜色值
//x,y:坐标
//返回值:此点的颜色
uint32_t NT35510_ReadPoint(uint16_t x,uint16_t y)
{
 	uint16_t r=0,g=0,b=0;

 	NT35510_SetCursor(x,y);
	NT35510_WriteCommand(0X2E00);	//5510 发送读GRAM指令
 	r=NT35510_ReadData();								//dummy Read
 	r=NT35510_ReadData();  		  						//实际坐标颜色
	b=NT35510_ReadData();
	g=r&0XFF;		//对于9341/5310/5510,第一次读取的是RG的值,R在前,G在后,各占8位
	g<<=8;
	return (((r>>11)<<11)|((g>>10)<<5)|(b>>11));	//ILI9341/NT35310/NT35510需要公式转换一下
}
//LCD开启显示
void NT35510_DisplayOn(void)
{
	NT35510_WriteCommand(0X2900);	//开启显示
}
//LCD关闭显示
void NT35510_DisplayOff(void)
{
	NT35510_WriteCommand(0X2800);	//关闭显示
}
//设置光标位置(对RGB屏无效)
//Xpos:横坐标
//Ypos:纵坐标
void NT35510_SetCursor(uint16_t Xpos, uint16_t Ypos)
{

    NT35510_WriteCommand(0X2A00);NT35510_WriteData(Xpos>>8);
    NT35510_WriteCommand(0X2A00+1);NT35510_WriteData(Xpos&0XFF);
    NT35510_WriteCommand(0X2B00);NT35510_WriteData(Ypos>>8);
    NT35510_WriteCommand(0X2B00+1);NT35510_WriteData(Ypos&0XFF);

}

//设置窗口(对RGB屏无效),并自动设置画点坐标到窗口左上角(sx,sy).
//sx,sy:窗口起始坐标(左上角)
//width,height:窗口宽度和高度,必须大于0!!
//窗体大小:width*height.
void NT35510_Set_Window(uint16_t sx,uint16_t sy,uint16_t width,uint16_t height)
{
	uint16_t twidth,theight;
	twidth=sx+width-1;
	theight=sy+height-1;

    NT35510_WriteCommand(0X2A00);NT35510_WriteData(sx>>8);
    NT35510_WriteCommand(0X2A00+1);NT35510_WriteData(sx&0XFF);
    NT35510_WriteCommand(0X2A00+2);NT35510_WriteData(twidth>>8);
    NT35510_WriteCommand(0X2A00+3);NT35510_WriteData(twidth&0XFF);
    NT35510_WriteCommand(0X2B00);NT35510_WriteData(sy>>8);
    NT35510_WriteCommand(0X2B00+1);NT35510_WriteData(sy&0XFF);
    NT35510_WriteCommand(0X2B00+2);NT35510_WriteData(theight>>8);
    NT35510_WriteCommand(0X2B00+3);NT35510_WriteData(theight&0XFF);

}

//开始写GRAM
void NT35510_WriteRAM_Prepare(void)
{
 	NT35510_WriteCommand(0X2C00);
}

//清屏函数
//color:要清屏的填充色
void NT35510_Clear(uint32_t color)
{
	uint32_t index,totalpoint;

	totalpoint =NT35510_WIDTH * NT35510_HEIGHT;
	NT35510_SetCursor(0x0000,0x0000);			//设置光标位置
	NT35510_WriteRAM_Prepare();     		//开始写入GRAM
	for(index=0;index<totalpoint;index++)
	{
		NT35510_WRITE_DATA=color;
	}
}



void NT35510_Init() {
	NT35510_HardwareInit();
    NT35510_Bl(1);
    NT35510_Reset();
    // command list is based on https://github.com/martnak/STM32-NT35510
    // SOFTWARE RESET

    uint16_t id;
    NT35510_WriteCommand(0XDA00);	
    id=NT35510_ReadData();		//读回0X00	 
    NT35510_WriteCommand(0XDB00);	
    id=NT35510_ReadData();		//读回0X80
    id<<=8;	
    NT35510_WriteCommand(0XDC00);	
    id|=NT35510_ReadData();		//读回0X00
	printf("id = %x \r\n\r\n",id);

    NT35510_SetRegister(0xF000,0x55);
    NT35510_SetRegister(0xF001,0xAA);
    NT35510_SetRegister(0xF002,0x52);
    NT35510_SetRegister(0xF003,0x08);
    NT35510_SetRegister(0xF004,0x01);
    //AVDD Set AVDD 5.2V
    NT35510_SetRegister(0xB000,0x0D);
    NT35510_SetRegister(0xB001,0x0D);
    NT35510_SetRegister(0xB002,0x0D);
    //AVDD ratio
    NT35510_SetRegister(0xB600,0x34);
    NT35510_SetRegister(0xB601,0x34);
    NT35510_SetRegister(0xB602,0x34);
    //AVEE -5.2V
    NT35510_SetRegister(0xB100,0x0D);
    NT35510_SetRegister(0xB101,0x0D);
    NT35510_SetRegister(0xB102,0x0D);
    //AVEE ratio
    NT35510_SetRegister(0xB700,0x34);
    NT35510_SetRegister(0xB701,0x34);
    NT35510_SetRegister(0xB702,0x34);
    //VCL -2.5V
    NT35510_SetRegister(0xB200,0x00);
    NT35510_SetRegister(0xB201,0x00);
    NT35510_SetRegister(0xB202,0x00);
    //VCL ratio
    NT35510_SetRegister(0xB800,0x24);
    NT35510_SetRegister(0xB801,0x24);
    NT35510_SetRegister(0xB802,0x24);
    //VGH 15V (Free pump)
    NT35510_SetRegister(0xBF00,0x01);
    NT35510_SetRegister(0xB300,0x0F);
    NT35510_SetRegister(0xB301,0x0F);
    NT35510_SetRegister(0xB302,0x0F);
    //VGH ratio
    NT35510_SetRegister(0xB900,0x34);
    NT35510_SetRegister(0xB901,0x34);
    NT35510_SetRegister(0xB902,0x34);
    //VGL_REG -10V
    NT35510_SetRegister(0xB500,0x08);
    NT35510_SetRegister(0xB501,0x08);
    NT35510_SetRegister(0xB502,0x08);
    NT35510_SetRegister(0xC200,0x03);
    //VGLX ratio
    NT35510_SetRegister(0xBA00,0x24);
    NT35510_SetRegister(0xBA01,0x24);
    NT35510_SetRegister(0xBA02,0x24);
    //VGMP/VGSP 4.5V/0V
    NT35510_SetRegister(0xBC00,0x00);
    NT35510_SetRegister(0xBC01,0x78);
    NT35510_SetRegister(0xBC02,0x00);
    //VGMN/VGSN -4.5V/0V
    NT35510_SetRegister(0xBD00,0x00);
    NT35510_SetRegister(0xBD01,0x78);
    NT35510_SetRegister(0xBD02,0x00);
    //VCOM
    NT35510_SetRegister(0xBE00,0x00);
    NT35510_SetRegister(0xBE01,0x64);
    //Gamma Setting
    NT35510_SetRegister(0xD100,0x00);
    NT35510_SetRegister(0xD101,0x33);
    NT35510_SetRegister(0xD102,0x00);
    NT35510_SetRegister(0xD103,0x34);
    NT35510_SetRegister(0xD104,0x00);
    NT35510_SetRegister(0xD105,0x3A);
    NT35510_SetRegister(0xD106,0x00);
    NT35510_SetRegister(0xD107,0x4A);
    NT35510_SetRegister(0xD108,0x00);
    NT35510_SetRegister(0xD109,0x5C);
    NT35510_SetRegister(0xD10A,0x00);
    NT35510_SetRegister(0xD10B,0x81);
    NT35510_SetRegister(0xD10C,0x00);
    NT35510_SetRegister(0xD10D,0xA6);
    NT35510_SetRegister(0xD10E,0x00);
    NT35510_SetRegister(0xD10F,0xE5);
    NT35510_SetRegister(0xD110,0x01);
    NT35510_SetRegister(0xD111,0x13);
    NT35510_SetRegister(0xD112,0x01);
    NT35510_SetRegister(0xD113,0x54);
    NT35510_SetRegister(0xD114,0x01);
    NT35510_SetRegister(0xD115,0x82);
    NT35510_SetRegister(0xD116,0x01);
    NT35510_SetRegister(0xD117,0xCA);
    NT35510_SetRegister(0xD118,0x02);
    NT35510_SetRegister(0xD119,0x00);
    NT35510_SetRegister(0xD11A,0x02);
    NT35510_SetRegister(0xD11B,0x01);
    NT35510_SetRegister(0xD11C,0x02);
    NT35510_SetRegister(0xD11D,0x34);
    NT35510_SetRegister(0xD11E,0x02);
    NT35510_SetRegister(0xD11F,0x67);
    NT35510_SetRegister(0xD120,0x02);
    NT35510_SetRegister(0xD121,0x84);
    NT35510_SetRegister(0xD122,0x02);
    NT35510_SetRegister(0xD123,0xA4);
    NT35510_SetRegister(0xD124,0x02);
    NT35510_SetRegister(0xD125,0xB7);
    NT35510_SetRegister(0xD126,0x02);
    NT35510_SetRegister(0xD127,0xCF);
    NT35510_SetRegister(0xD128,0x02);
    NT35510_SetRegister(0xD129,0xDE);
    NT35510_SetRegister(0xD12A,0x02);
    NT35510_SetRegister(0xD12B,0xF2);
    NT35510_SetRegister(0xD12C,0x02);
    NT35510_SetRegister(0xD12D,0xFE);
    NT35510_SetRegister(0xD12E,0x03);
    NT35510_SetRegister(0xD12F,0x10);
    NT35510_SetRegister(0xD130,0x03);
    NT35510_SetRegister(0xD131,0x33);
    NT35510_SetRegister(0xD132,0x03);
    NT35510_SetRegister(0xD133,0x6D);
    NT35510_SetRegister(0xD200,0x00);
    NT35510_SetRegister(0xD201,0x33);
    NT35510_SetRegister(0xD202,0x00);
    NT35510_SetRegister(0xD203,0x34);
    NT35510_SetRegister(0xD204,0x00);
    NT35510_SetRegister(0xD205,0x3A);
    NT35510_SetRegister(0xD206,0x00);
    NT35510_SetRegister(0xD207,0x4A);
    NT35510_SetRegister(0xD208,0x00);
    NT35510_SetRegister(0xD209,0x5C);
    NT35510_SetRegister(0xD20A,0x00);

    NT35510_SetRegister(0xD20B,0x81);
    NT35510_SetRegister(0xD20C,0x00);
    NT35510_SetRegister(0xD20D,0xA6);
    NT35510_SetRegister(0xD20E,0x00);
    NT35510_SetRegister(0xD20F,0xE5);
    NT35510_SetRegister(0xD210,0x01);
    NT35510_SetRegister(0xD211,0x13);
    NT35510_SetRegister(0xD212,0x01);
    NT35510_SetRegister(0xD213,0x54);
    NT35510_SetRegister(0xD214,0x01);
    NT35510_SetRegister(0xD215,0x82);
    NT35510_SetRegister(0xD216,0x01);
    NT35510_SetRegister(0xD217,0xCA);
    NT35510_SetRegister(0xD218,0x02);
    NT35510_SetRegister(0xD219,0x00);
    NT35510_SetRegister(0xD21A,0x02);
    NT35510_SetRegister(0xD21B,0x01);
    NT35510_SetRegister(0xD21C,0x02);
    NT35510_SetRegister(0xD21D,0x34);
    NT35510_SetRegister(0xD21E,0x02);
    NT35510_SetRegister(0xD21F,0x67);
    NT35510_SetRegister(0xD220,0x02);
    NT35510_SetRegister(0xD221,0x84);
    NT35510_SetRegister(0xD222,0x02);
    NT35510_SetRegister(0xD223,0xA4);
    NT35510_SetRegister(0xD224,0x02);
    NT35510_SetRegister(0xD225,0xB7);
    NT35510_SetRegister(0xD226,0x02);
    NT35510_SetRegister(0xD227,0xCF);
    NT35510_SetRegister(0xD228,0x02);
    NT35510_SetRegister(0xD229,0xDE);
    NT35510_SetRegister(0xD22A,0x02);
    NT35510_SetRegister(0xD22B,0xF2);
    NT35510_SetRegister(0xD22C,0x02);
    NT35510_SetRegister(0xD22D,0xFE);
    NT35510_SetRegister(0xD22E,0x03);
    NT35510_SetRegister(0xD22F,0x10);
    NT35510_SetRegister(0xD230,0x03);
    NT35510_SetRegister(0xD231,0x33);
    NT35510_SetRegister(0xD232,0x03);
    NT35510_SetRegister(0xD233,0x6D);
    NT35510_SetRegister(0xD300,0x00);
    NT35510_SetRegister(0xD301,0x33);
    NT35510_SetRegister(0xD302,0x00);
    NT35510_SetRegister(0xD303,0x34);
    NT35510_SetRegister(0xD304,0x00);
    NT35510_SetRegister(0xD305,0x3A);
    NT35510_SetRegister(0xD306,0x00);
    NT35510_SetRegister(0xD307,0x4A);
    NT35510_SetRegister(0xD308,0x00);
    NT35510_SetRegister(0xD309,0x5C);
    NT35510_SetRegister(0xD30A,0x00);

    NT35510_SetRegister(0xD30B,0x81);
    NT35510_SetRegister(0xD30C,0x00);
    NT35510_SetRegister(0xD30D,0xA6);
    NT35510_SetRegister(0xD30E,0x00);
    NT35510_SetRegister(0xD30F,0xE5);
    NT35510_SetRegister(0xD310,0x01);
    NT35510_SetRegister(0xD311,0x13);
    NT35510_SetRegister(0xD312,0x01);
    NT35510_SetRegister(0xD313,0x54);
    NT35510_SetRegister(0xD314,0x01);
    NT35510_SetRegister(0xD315,0x82);
    NT35510_SetRegister(0xD316,0x01);
    NT35510_SetRegister(0xD317,0xCA);
    NT35510_SetRegister(0xD318,0x02);
    NT35510_SetRegister(0xD319,0x00);
    NT35510_SetRegister(0xD31A,0x02);
    NT35510_SetRegister(0xD31B,0x01);
    NT35510_SetRegister(0xD31C,0x02);
    NT35510_SetRegister(0xD31D,0x34);
    NT35510_SetRegister(0xD31E,0x02);
    NT35510_SetRegister(0xD31F,0x67);
    NT35510_SetRegister(0xD320,0x02);
    NT35510_SetRegister(0xD321,0x84);
    NT35510_SetRegister(0xD322,0x02);
    NT35510_SetRegister(0xD323,0xA4);
    NT35510_SetRegister(0xD324,0x02);
    NT35510_SetRegister(0xD325,0xB7);
    NT35510_SetRegister(0xD326,0x02);
    NT35510_SetRegister(0xD327,0xCF);
    NT35510_SetRegister(0xD328,0x02);
    NT35510_SetRegister(0xD329,0xDE);
    NT35510_SetRegister(0xD32A,0x02);
    NT35510_SetRegister(0xD32B,0xF2);
    NT35510_SetRegister(0xD32C,0x02);
    NT35510_SetRegister(0xD32D,0xFE);
    NT35510_SetRegister(0xD32E,0x03);
    NT35510_SetRegister(0xD32F,0x10);
    NT35510_SetRegister(0xD330,0x03);
    NT35510_SetRegister(0xD331,0x33);
    NT35510_SetRegister(0xD332,0x03);
    NT35510_SetRegister(0xD333,0x6D);
    NT35510_SetRegister(0xD400,0x00);
    NT35510_SetRegister(0xD401,0x33);
    NT35510_SetRegister(0xD402,0x00);
    NT35510_SetRegister(0xD403,0x34);
    NT35510_SetRegister(0xD404,0x00);
    NT35510_SetRegister(0xD405,0x3A);
    NT35510_SetRegister(0xD406,0x00);
    NT35510_SetRegister(0xD407,0x4A);
    NT35510_SetRegister(0xD408,0x00);
    NT35510_SetRegister(0xD409,0x5C);
    NT35510_SetRegister(0xD40A,0x00);
    NT35510_SetRegister(0xD40B,0x81);

    NT35510_SetRegister(0xD40C,0x00);
    NT35510_SetRegister(0xD40D,0xA6);
    NT35510_SetRegister(0xD40E,0x00);
    NT35510_SetRegister(0xD40F,0xE5);
    NT35510_SetRegister(0xD410,0x01);
    NT35510_SetRegister(0xD411,0x13);
    NT35510_SetRegister(0xD412,0x01);
    NT35510_SetRegister(0xD413,0x54);
    NT35510_SetRegister(0xD414,0x01);
    NT35510_SetRegister(0xD415,0x82);
    NT35510_SetRegister(0xD416,0x01);
    NT35510_SetRegister(0xD417,0xCA);
    NT35510_SetRegister(0xD418,0x02);
    NT35510_SetRegister(0xD419,0x00);
    NT35510_SetRegister(0xD41A,0x02);
    NT35510_SetRegister(0xD41B,0x01);
    NT35510_SetRegister(0xD41C,0x02);
    NT35510_SetRegister(0xD41D,0x34);
    NT35510_SetRegister(0xD41E,0x02);
    NT35510_SetRegister(0xD41F,0x67);
    NT35510_SetRegister(0xD420,0x02);
    NT35510_SetRegister(0xD421,0x84);
    NT35510_SetRegister(0xD422,0x02);
    NT35510_SetRegister(0xD423,0xA4);
    NT35510_SetRegister(0xD424,0x02);
    NT35510_SetRegister(0xD425,0xB7);
    NT35510_SetRegister(0xD426,0x02);
    NT35510_SetRegister(0xD427,0xCF);
    NT35510_SetRegister(0xD428,0x02);
    NT35510_SetRegister(0xD429,0xDE);
    NT35510_SetRegister(0xD42A,0x02);
    NT35510_SetRegister(0xD42B,0xF2);
    NT35510_SetRegister(0xD42C,0x02);
    NT35510_SetRegister(0xD42D,0xFE);
    NT35510_SetRegister(0xD42E,0x03);
    NT35510_SetRegister(0xD42F,0x10);
    NT35510_SetRegister(0xD430,0x03);
    NT35510_SetRegister(0xD431,0x33);
    NT35510_SetRegister(0xD432,0x03);
    NT35510_SetRegister(0xD433,0x6D);
    NT35510_SetRegister(0xD500,0x00);
    NT35510_SetRegister(0xD501,0x33);
    NT35510_SetRegister(0xD502,0x00);
    NT35510_SetRegister(0xD503,0x34);
    NT35510_SetRegister(0xD504,0x00);
    NT35510_SetRegister(0xD505,0x3A);
    NT35510_SetRegister(0xD506,0x00);
    NT35510_SetRegister(0xD507,0x4A);
    NT35510_SetRegister(0xD508,0x00);
    NT35510_SetRegister(0xD509,0x5C);
    NT35510_SetRegister(0xD50A,0x00);
    NT35510_SetRegister(0xD50B,0x81);

    NT35510_SetRegister(0xD50C,0x00);
    NT35510_SetRegister(0xD50D,0xA6);
    NT35510_SetRegister(0xD50E,0x00);
    NT35510_SetRegister(0xD50F,0xE5);
    NT35510_SetRegister(0xD510,0x01);
    NT35510_SetRegister(0xD511,0x13);
    NT35510_SetRegister(0xD512,0x01);
    NT35510_SetRegister(0xD513,0x54);
    NT35510_SetRegister(0xD514,0x01);
    NT35510_SetRegister(0xD515,0x82);
    NT35510_SetRegister(0xD516,0x01);
    NT35510_SetRegister(0xD517,0xCA);
    NT35510_SetRegister(0xD518,0x02);
    NT35510_SetRegister(0xD519,0x00);
    NT35510_SetRegister(0xD51A,0x02);
    NT35510_SetRegister(0xD51B,0x01);
    NT35510_SetRegister(0xD51C,0x02);
    NT35510_SetRegister(0xD51D,0x34);
    NT35510_SetRegister(0xD51E,0x02);
    NT35510_SetRegister(0xD51F,0x67);
    NT35510_SetRegister(0xD520,0x02);
    NT35510_SetRegister(0xD521,0x84);
    NT35510_SetRegister(0xD522,0x02);
    NT35510_SetRegister(0xD523,0xA4);
    NT35510_SetRegister(0xD524,0x02);
    NT35510_SetRegister(0xD525,0xB7);
    NT35510_SetRegister(0xD526,0x02);
    NT35510_SetRegister(0xD527,0xCF);
    NT35510_SetRegister(0xD528,0x02);
    NT35510_SetRegister(0xD529,0xDE);
    NT35510_SetRegister(0xD52A,0x02);
    NT35510_SetRegister(0xD52B,0xF2);
    NT35510_SetRegister(0xD52C,0x02);
    NT35510_SetRegister(0xD52D,0xFE);
    NT35510_SetRegister(0xD52E,0x03);
    NT35510_SetRegister(0xD52F,0x10);
    NT35510_SetRegister(0xD530,0x03);
    NT35510_SetRegister(0xD531,0x33);
    NT35510_SetRegister(0xD532,0x03);
    NT35510_SetRegister(0xD533,0x6D);
    NT35510_SetRegister(0xD600,0x00);
    NT35510_SetRegister(0xD601,0x33);
    NT35510_SetRegister(0xD602,0x00);
    NT35510_SetRegister(0xD603,0x34);
    NT35510_SetRegister(0xD604,0x00);
    NT35510_SetRegister(0xD605,0x3A);
    NT35510_SetRegister(0xD606,0x00);
    NT35510_SetRegister(0xD607,0x4A);
    NT35510_SetRegister(0xD608,0x00);
    NT35510_SetRegister(0xD609,0x5C);
    NT35510_SetRegister(0xD60A,0x00);
    NT35510_SetRegister(0xD60B,0x81);

    NT35510_SetRegister(0xD60C,0x00);
    NT35510_SetRegister(0xD60D,0xA6);
    NT35510_SetRegister(0xD60E,0x00);
    NT35510_SetRegister(0xD60F,0xE5);
    NT35510_SetRegister(0xD610,0x01);
    NT35510_SetRegister(0xD611,0x13);
    NT35510_SetRegister(0xD612,0x01);
    NT35510_SetRegister(0xD613,0x54);
    NT35510_SetRegister(0xD614,0x01);
    NT35510_SetRegister(0xD615,0x82);
    NT35510_SetRegister(0xD616,0x01);
    NT35510_SetRegister(0xD617,0xCA);
    NT35510_SetRegister(0xD618,0x02);
    NT35510_SetRegister(0xD619,0x00);
    NT35510_SetRegister(0xD61A,0x02);
    NT35510_SetRegister(0xD61B,0x01);
    NT35510_SetRegister(0xD61C,0x02);
    NT35510_SetRegister(0xD61D,0x34);
    NT35510_SetRegister(0xD61E,0x02);
    NT35510_SetRegister(0xD61F,0x67);
    NT35510_SetRegister(0xD620,0x02);
    NT35510_SetRegister(0xD621,0x84);
    NT35510_SetRegister(0xD622,0x02);
    NT35510_SetRegister(0xD623,0xA4);
    NT35510_SetRegister(0xD624,0x02);
    NT35510_SetRegister(0xD625,0xB7);
    NT35510_SetRegister(0xD626,0x02);
    NT35510_SetRegister(0xD627,0xCF);
    NT35510_SetRegister(0xD628,0x02);
    NT35510_SetRegister(0xD629,0xDE);
    NT35510_SetRegister(0xD62A,0x02);
    NT35510_SetRegister(0xD62B,0xF2);
    NT35510_SetRegister(0xD62C,0x02);
    NT35510_SetRegister(0xD62D,0xFE);
    NT35510_SetRegister(0xD62E,0x03);
    NT35510_SetRegister(0xD62F,0x10);
    NT35510_SetRegister(0xD630,0x03);
    NT35510_SetRegister(0xD631,0x33);
    NT35510_SetRegister(0xD632,0x03);
    NT35510_SetRegister(0xD633,0x6D);
    //LV2 Page 0 enable
    NT35510_SetRegister(0xF000,0x55);
    NT35510_SetRegister(0xF001,0xAA);
    NT35510_SetRegister(0xF002,0x52);
    NT35510_SetRegister(0xF003,0x08);
    NT35510_SetRegister(0xF004,0x00);
    //Display control
    NT35510_SetRegister(0xB100, 0xCC);
    NT35510_SetRegister(0xB101, 0x00);
    //Source hold time
    NT35510_SetRegister(0xB600,0x05);
    //Gate EQ control
    NT35510_SetRegister(0xB700,0x70);
    NT35510_SetRegister(0xB701,0x70);
    //Source EQ control (Mode 2)
    NT35510_SetRegister(0xB800,0x01);
    NT35510_SetRegister(0xB801,0x03);
    NT35510_SetRegister(0xB802,0x03);
    NT35510_SetRegister(0xB803,0x03);
    //Inversion mode (2-dot)
    NT35510_SetRegister(0xBC00,0x02);
    NT35510_SetRegister(0xBC01,0x00);
    NT35510_SetRegister(0xBC02,0x00);
    //Timing control 4H w/ 4-delay
    NT35510_SetRegister(0xC900,0xD0);
    NT35510_SetRegister(0xC901,0x02);
    NT35510_SetRegister(0xC902,0x50);
    NT35510_SetRegister(0xC903,0x50);
    NT35510_SetRegister(0xC904,0x50);
    NT35510_SetRegister(0x3500,0x00);
    NT35510_SetRegister(0x3A00,0x55);  //16-bit/pixel
    NT35510_WriteCommand(0x1100);
    NT35510_DelayMs(1);
    NT35510_WriteCommand(0x2900);
    NT35510_Set_Window(0,0,NT35510_WIDTH,NT35510_HEIGHT);
    NT35510_Clear(NT35510_RED);
}


